package com.bw.task.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.bw.library.mvp.view.BaseFragment;
import com.bw.task.R;
import com.bw.task.activity.EWMActivity;
import com.bw.task.customview.MyView;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.uuzuche.lib_zxing.activity.CodeUtils;


public class TowFragment extends BaseFragment {

    private Button ewm;
    private Button smewm;
    private ImageView imgewm;
    private MyView myView;
    private Button button;
    private Button fx;

    @Override
    public int bandLayout() {
        return R.layout.fragment_tow;
    }

    @Override
    public void initData() {
        ewm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bitmap bitmap = CodeUtils.createImage("晚上好", 200, 200, null);
                imgewm.setImageBitmap(bitmap);
            }
        });
        smewm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().startActivity(new Intent(getContext(), EWMActivity.class));
            }
        });
        imgewm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TranslateAnimation translateAnimation = new TranslateAnimation(0, 300, 0, 0);
                translateAnimation.setDuration(3000);

                AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
                alphaAnimation.setDuration(2000);

                imgewm.startAnimation(alphaAnimation);
            }
        });
        imgewm.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                PopupWindow popupWindow = new PopupWindow();
                popupWindow.setHeight(300);
                popupWindow.setWidth(300);

                View inflate = LayoutInflater.from(getContext()).inflate(R.layout.slideminu, null);
                popupWindow.setContentView(inflate);
                popupWindow.dismiss();
                popupWindow.showAsDropDown(imgewm);
                return true;
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myView.addimgView();
            }
        });
        fx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(getContext(), "https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2858426577,4189650377&fm=26&gp=0.jpg");//网络图片
                new ShareAction(getActivity())
                        .withText("hello").setDisplayList(SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN,SHARE_MEDIA.QZONE)
                        .withMedia(image)
                        .setCallback(new UMShareListener() {
                            @Override
                            public void onStart(SHARE_MEDIA share_media) {

                            }

                            @Override
                            public void onResult(SHARE_MEDIA share_media) {

                            }

                            @Override
                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                Toast.makeText(getActivity(), ""+throwable.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onCancel(SHARE_MEDIA share_media) {

                            }
                        }).open();
            }
        });
    }

    @Override
    public void initView() {

        ewm = (Button) findViewById(R.id.ewm);
        smewm = (Button) findViewById(R.id.smewm);
        imgewm = (ImageView) findViewById(R.id.imgewm);
        myView = (MyView) findViewById(R.id.myView);
        button = (Button) findViewById(R.id.button);
        fx = (Button) findViewById(R.id.fx);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(getContext()).onActivityResult(requestCode, resultCode, data);
    }
}